﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Common.Utilities.Dispatcher;
using Common.Utilities;

namespace Workflows.Components.TextMining.EnumerationObjects
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class PdfDocListOutput:ResultBase
    {
        #region props
        private string _ResultFilePath;
        /// <summary></summary>
        public string ResultFilePath
        {
            get
            {
                return this._ResultFilePath;
            }
            set
            {
                this._ResultFilePath = value;
            }
        }

        private int _FileCount;
        /// <summary></summary>
        public int FileCount
        {
            get
            {
                return this._FileCount;
            }
            set
            {
                this._FileCount = value;
            }
        }
        #endregion

        #region ctor
        /// <summary>
        /// 
        /// </summary>
        public PdfDocListOutput()
            : base(Guid.Empty, Guid.Empty)
        {
            this._ResultFilePath = string.Empty;
            this._FileCount = 0;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="componentID"></param>
        /// <param name="jobTicketID"></param>
        /// <param name="resultFilePath"></param>
        /// <param name="fileCount"></param>
        public PdfDocListOutput(Guid componentID, Guid jobTicketID,
            string resultFilePath, int fileCount)
            : base(componentID, jobTicketID)
        {
            this._ResultFilePath = resultFilePath;
            this._FileCount = fileCount;
        }
        #endregion

        /// <summary>
        /// 
        /// </summary>
        /// <param name="xDoc"></param>
        /// <param name="parentNode"></param>
        /// <returns></returns>
        public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
        {
            XmlNode xNode = XmlDataUtil.AddElement(ref xDoc, parentNode, "Output");
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "Type", this.GetType().FullName);
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "WorkerID", this.OwnerWorkerInstanceID.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "FinishTime", this.FinishTime.ToString());

            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "ResultFilePath", this.ResultFilePath);
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "FileCount", this.FileCount.ToString());
            
            return xNode;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="xNode"></param>
        /// <returns></returns>
        public override ResultBase Instantiate(XmlNode xNode)
        {
            if (xNode.Attributes.GetNamedItem("Type").Value == this.GetType().FullName)
            {
                PdfDocListOutput output = new PdfDocListOutput();

                output.ResultFilePath = XmlDataUtil.GetAttributeValue(xNode, "ResultFilePath", "");
                output.FileCount = int.Parse(XmlDataUtil.GetAttributeValue(xNode, "FileCount", "0"));
                
                return output;
            }
            else
            {
                throw new Exception("Unable to instantiate output: invalid type specified in xml node");
            }
        }
    }
}
